/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.potomak.patientmanager.tools;

import java.math.BigDecimal;

/**
 *
 * @author mobile
 */
public class BMICalculator {
    
    public static double round(double d, int decimalPlace){
        // see the Javadoc about why we use a String in the constructor
        // http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigDecimal.html#BigDecimal(double)
        BigDecimal bd = new BigDecimal(Double.toString(d));
        bd = bd.setScale(decimalPlace,BigDecimal.ROUND_HALF_UP);
        return bd.doubleValue();
    }
    
    public static Double calculate(Double weight, Double height) {
        Double BMI = round((weight / Math.pow(height,2)), 2);
        
        return round(BMI,2);
    }
}
